package com.om.base;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class DynamicProxyHandler <T> implements InvocationHandler  {
	protected T business;
	  
	public T bind(T obj) { 
        this.business = obj; 
        return (T) Proxy.newProxyInstance( 
                //被代理类的ClassLoader
                obj.getClass().getClassLoader(), 
                //要被代理的接口,本方法返回对象会自动声称实现了这些接口 
                obj.getClass().getInterfaces(), 
                //代理处理器对象 
                this); 
    }
	
	@Override
	public Object invoke(Object proxy, Method method, Object[] args)
			throws Throwable {
		
		this.beforeInvoke(method,args);
		Object resault  = method.invoke(args);
		afterInvoke(method,args);
		
		return resault ;
	}
	
	
	public void beforeInvoke(Method method, Object[] args)
			throws Throwable {
		

	}
	
	public void afterInvoke(Method method, Object[] args)
			throws Throwable {
		
		
	}
	
	
	

}
